package com.nowcoder.community.dao;

import com.nowcoder.community.entity.LoginTicket;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author szq
 * @create 2023-01-20 16:27
 * @description 登录凭证数据访问层
 */
@Mapper
@Deprecated // 使用Redis优化
public interface LoginTicketMapper {
    String TABLE_NAME = " login_ticket ";
    String INSERT_FIELDS = " user_id,ticket,expired,status ";
    String SELECT_FIELDS = " id, " + INSERT_FIELDS;

    // 新增凭证
    //@Select({"insert into", TABLE_NAME, "(", INSERT_FIELDS, ") values(#{userId},#{ticket},#{expired},#{status})"})
    //@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    Integer insertLoginTicket(LoginTicket loginTicket);

    // 查询凭证
    @Select({"select", SELECT_FIELDS, " from ", TABLE_NAME, "where ticket = #{ticket}"})
    LoginTicket selectByTicket(String ticket);

    // 更新状态 0-有效; 1-无效(已删除状态);
    @Update({"update ", TABLE_NAME, " set status = #{status} where ticket = #{ticket}"})
    Integer updateStatus(String ticket, int status);
}
